﻿<style>
    

    .xm-select-dl{
        width:360px !important;
    }
    .xm-select-linkage .xm-select-linkage-group li {
        height:24px;
        line-height:24px
    }
    .xm-select-linkage .xm-select-linkage-group li span{
       line-height:24px
    }

</style>
<script type="text/html" template>
    <title>{{layui.setter.MenuName}}-{{layui.setter.name}}</title>
</script>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <script type="text/html" template>
            <a><cite>{{layui.setter.MenuName}}</cite></a>
        </script>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-inline">
                        <input type="text" name="key" id="key" placeholder="交易单号/流水单号" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">账单类型</label>
                    <div class="layui-input-inline">
                        <select id="seltype" name="seltype">
                            <option value=""></option>
                            <option value="0">订单支付</option>
                            <option value="1">订单退款</option>
                            <option value="2">其他</option>
                        </select>
                    </div>
                    <label class="layui-form-label">账单状态</label>
                    <div class="layui-input-inline">
                        <select id="selstate" name="selstate">
                            <option value=""></option>
                            <option value="0">未完成</option>
                            <option value="1">已完成</option>
                            <option value="2">取消</option>
                            <option value="3">交易失败</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">用户</label>
                    <div class="layui-input-inline">
                        <input type="text" name="seluser" id="seluser" placeholder="姓名/会员编号" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="test6" readonly="readonly" placeholder=" - ">
                    </div>
                    <!--<label class="layui-form-label">店铺</label>
                    <div class="layui-input-inline">
                        <select name="storeId" xm-select="storeId" xm-select-search xm-select-skin="default">
                            <option value=""></option>
                        </select>
                    </div>-->
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-delete">
                        <i class="layui-icon layui-icon-delete layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <script type="text/html" template lay-url="{{ layui.setter.APIUrl }}/shop/billflowMgr/GetButtonRight" lay-type="post" lay-done="layui.data.setActive()">
                    {{ d.Data }}
                </script>
            </div>
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>      
        </div>
    </div>
</div>
<script>


    layui.use('shop_billflow', layui.factory('shop_billflow')).use(['admin', 'table', 'form', 'laydate', 'formSelects'], function () {

        var $ = layui.$
        , admin = layui.admin
        , view = layui.view
        , table = layui.table
        , form = layui.form;
        var laydate = layui.laydate;
        var formSelects = layui.formSelects;

        laydate.render({
            elem: '#test6',
            range: '~' //指定元素
        });

        formSelects.config('storeId', {
            keyName: 'title',            //自定义返回数据中name的key, 默认 name
            keyVal: 'id',            //自定义返回数据中value的key, 默认 value
            keyChildren: 'children',    //联动多选自定义children
        });

        admin.req({
            url: layui.setter.APIUrl + '/shop/storeMgr/customerQueryChildren2', //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                layui.formSelects.data('storeId', 'local', {
                    arr: res.Data,
                    linkage: true,
                    linkageWidth: 120
                });
            }
        });
        formSelects.on('storeId', function (id, vals, val, isAdd, isDisabled) {
            if (isAdd == true) {
                if (val.value.indexOf("/") <= 0) {  //多级选择时,第一级无法选中
                    isAdd = false;
                    return false;
                }
            }
        });

        form.render(null, 'app-content-list');

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            var dataTime = $("#test6").val();
            if (dataTime) {
                var times = dataTime.split('~');
                field["startTime"] = times[0].trim();
                field["endTime"] = times[1].trim();
            }
            else {
                field["startTime"] = "";
                field["endTime"] = "";
            }
            //执行重载
            table.reload('LAY-app-content-list', {
                where: field,
                page:{
                    curr:1 //重新从第1页开始
                }
            });
        });

        form.on('submit(LAY-app-contlist-delete)', function (data) {
            $("#key").val("");
            $("#seltype").val('');
            $("#selstate").val('');
            $("#seluser").val('');
            //$("#storeId").val('');
            layui.formSelects.value('storeId', []);
            $("#test6").val('');
            form.render('select');

            var field = data.field;
            field.key = "";
            field.seltype = "";
            field.selstate = "";
            field.seluser = "";
            field.storeId = "";
            field.startTime = "";
            field.endTime = "";
            //执行重载
            table.reload('LAY-app-content-list', {
                where: field,
                page: {
                    curr: 1 //重新从第1页开始
                }
            });
        });
    });
    
    layui.data.setActive = function () { 
    
        layui.use(['form', 'admin', 'table'], function () {
                var $ = layui.$;
                var form = layui.form;
                var admin = layui.admin;
                var view = layui.view;
                var table = layui.table;
                 var active = {
                del: function () {
                    var checkStatus = table.checkStatus('LAY-app-content-list')
                    , checkData = checkStatus.data; //得到选中的数据

                    if (checkData.length === 0) {
                        return layer.msg('请选择数据');
                    }
                    var ids = "";
                    $.each(checkData, function (index, eobj) {
                        ids += "," + eobj.PID;
                    });
                    if (ids.indexOf(',') == 0)
                        ids = ids.substr(1);
                    //return layer.msg('已删除');
                    layer.confirm('确定删除吗？', function (index) {
                        admin.req({
                            url: layui.setter.APIUrl + '/shop/billflowMgr/BatchDelete' //实际使用请改成服务端真实接口
                          , data: { "ids": ids }
                              , type: "post"
                            //, success: function (res) {
                            //}
                          , done: function (res) {
                              layer.close(index); //执行关闭
                              layer.msg(res.ResultInfo);
                              table.reload('LAY-app-content-list');
                          }
                        });
                    });
                },
                //添加
               add: function (othis) {
                  //location.hash = '/shop/shop_billflow/addChild';           
                  admin.popup({
                      title: '添加信息'
                    , skin: 'layui-layer-lan'
                    , area: ['850px', '650px']
                    , id: 'LAY-popup-content-add'
                    , success: function (layero, index) {
                        view(this.id).render('/shop/shop_billflow/add').done(function () {
                            form.render(null, 'layuiadmin-app-form-list');

                            //监听提交
                            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                var field = data.field; //获取提交的字段
                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                //请求登入接口
                                admin.req({
                                    url: layui.setter.APIUrl + '/shop/billflowMgr/Add' //实际使用请改成服务端真实接口
                                  , data: field
                                  , type: "post"
                                  , done: function (res) {
                                      layer.close(index); //执行关闭
                                      layui.table.reload('LAY-app-content-list'); //重载表格
                                      layer.msg('新增成功');
                                  }
                                });
                            });
                        });
                    }
                  });
              }
            };

            $('.layui-btn.layuiadmin-btn-list').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });  
        });
    }

</script>
